﻿@model Member
@{
    ViewBag.Title = "添加用户";
    Layout = "~/Views/Shared/Master.cshtml";
}
@{Html.Telerik().Window().Name("AddMemberWindow").Title("添加用户").HtmlAttributes(new { @class = "ContentWindow" })
    .Buttons(buttons => buttons.Clear())
    .Content(
@<text>
@{using (Ajax.BeginForm<MemberController>(c => c.MemberAdd(null),
    new AjaxOptions { OnBegin = "BeforeSend", OnSuccess = "OnSuccess", OnFailure = "OnError" }))
  {
        <table>
            <tr>
                <th>医院</th>
                <td>
                    @Html.HiddenFor(model => model.ID)
                    @Html.HiddenFor(model => model.HospitalID)
                    @Html.DisplayFor(model => model.Hospital.Name)
                </td>
            </tr>
            <tr>
                <th>登录名<span style="color:red;">*</span></th>
                <td>@Html.TextBoxFor(model => model.LoginName)</td>
                <th><span style="color:red;visibility:hidden;" id="LoginName_alert">登录名不能为空</span></th>
            </tr>
            <tr>
                <th>真实姓名</th>
                <td>@Html.TextBoxFor(model => model.RealName)</td>
            </tr>
            <tr>
                <th>性别</th>
                <td>@Html.GenderEditorFor(model => model.Gender)</td>
            </tr>
            <tr>
                <th>电话</th>
                <td>@Html.TextBoxFor(model => model.Phone)</td>
            </tr>
            <tr>
                <th>E-mail</th>
                <td>@Html.TextBoxFor(model => model.Email)</td>
            </tr>
            <tr>
                <th>用户类型</th>
                <td>
                    @Html.MemberTypeDisplayFor(model => model.Type)
                    @Html.HiddenFor(model => model.Type)
                </td>
            </tr>
            <tr>
                <th>简介</th>
                <td>@Html.TextAreaFor(model => model.Profile)</td>
            </tr>
            <tr>
                <th>密码</th>
                <td>@Html.SecurePasswordFor(model => model.Passcode)</td>
            </tr>
            <tr>
                <th>再次输入密码</th>
                <td>@Html.SecurePassword("Passcode2")</td>
            </tr>
        </table>

        <input type="submit" onclick="validat();" id="btnAddMember" value="提交" />
      }
    }
  </text>)
    .Render();
}

@{Html.Telerik().Window().Modal(true).Visible(false)
    .Name("adding").Title("系统提示")
    .Buttons(buttons => buttons.Clear())
    .ClientEvents(window => window.OnOpen("OnAddingOpen"))
    .Content(
@<text>
正在添加，请稍后...
</text>)
    .Render();
}
@{Html.Telerik().Window().Modal(true).Visible(false)
    .Name("addError").Title("系统提示")
    .Buttons(buttons => buttons.Close())
    .ClientEvents(window => window.OnOpen("OnAddErrorOpen"))
    .Content(
@<text>
出现错误，请重试！
</text>)
    .Render();
}
<script type="text/javascript">
    function OnAddingOpen() {
        $("#adding").data("tWindow").center();
    }
    function OnAddErrorOpen() {
        $("#addError").data("tWindow").center();
    }
    function BeforeSend() {
        $("#adding").data("tWindow").open();
    }
    function OnSuccess(data) {
        if (data.ID) {
            var url = "@(Url.Action<MemberController>(c => c.MemberDetail(Guid.Empty)))";
           url = url.replace("@Guid.Empty", data.ID);
            window.location = url;
        } else {
            $("#addError").data("tWindow").open();
            $("#adding").data("tWindow").close();
        }
    }
    function OnError() {
        $("#addError").data("tWindow").open();
        $("#adding").data("tWindow").close();
    }
    $("#btnAddMember").click(function(){
        var txtPasscode = $("#Passcode");
        var txtPasscode2 = $("#Passcode2");
        var password = txtPasscode.val();
        var password2 = txtPasscode2.val();
        if (password != password2) {
            $("#divUploadError").dialog("open");
            return false;
        }
        var passcode = password.Base64Encode();
        txtPasscode.val(passcode);  //将密码Base64加密
        txtPasscode2.val(passcode);
    });
    function validat() {
        var isfalse = "";
        var valueLoginName = LoginName.value;
        if (valueLoginName == "") {
            LoginName_alert.style.visibility = "visible";
            isfalse = "false";
        }
        else {
            LoginName_alert.style.visibility = "hidden";
        }
        if (isfalse == "false") {
            return false;
        }
    }
</script>